package solution.linklist;

public class NodeOps {
    private Node head = new Node(0,"");

    public void add(Node node){
        Node temp = head;
        while (temp.next != null) temp = temp.next;
        temp.next = node;
    }

    public void list(){
        if (head.next == null) return;
        Node temp = head.next;
        while (temp != null){
            System.out.println(temp);
            temp = temp.next;
        }
    }

    public void addByOrder(Node node){
        Node temp = head; //头指针
        boolean flag = false;
        while (true){
            if (temp.next == null) return;
            if (temp.next.no > node.no) break;
            if (temp.next.no.equals(node.no)) flag = true;
            temp = temp.next;
        }
        if (flag) System.out.println("编号已存在");
        else node.next = temp.next;
             temp.next = node;
    }
}
